//
//  ViewController.m
//  06-UINavigationController
//
//  Created by dllo on 16/7/21.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#import "PushViewCOntroller.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 设置navigationBar的属性
    // 1.title 标题, 告诉用户, 这个视图控制器是干啥的
    self.title = @"我是标题, 你是啥";
    self.navigationItem.title = @"改变了标题";
    // 2.titleView 标题视图 (修改x, y 对视图本身没有影响)
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"德玛", @"诺克"]];
    segment.frame = CGRectMake(0, 0, 150, 44);
    self.navigationItem.titleView = segment;
    // 3.创建左边的leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    // 4.创建右边的rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(comeGo:)];
    // 5.leftBarButtonItems
    UIBarButtonItem *barBUttonItem = [[UIBarButtonItem alloc] initWithTitle:@"xxx" style:UIBarButtonItemStylePlain target:self action:@selector(comeGo:)];
    UIBarButtonItem *barBUttonSystemItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(comeGo:)];
    self.navigationItem.leftBarButtonItems = @[barBUttonItem,barBUttonSystemItem];
    // 6.rightBarButtonItems
    // barButtonItems 数组中放1-2个Item为最优
    // 7.是否隐藏NavigationBar(默认是NO, 不隐藏)YES:隐藏
    self.navigationController.navigationBarHidden = NO;
    // 等效为⬇️:
    self.navigationController.navigationBar.hidden = NO;
    // 8.navigationBar 的背景样式, 默认为Default , 是枚举类型
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    // 9.navigationBar的背景颜色
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10.barTintColor Bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    // 11.tintColor Bar上所有东西的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12.translucent 管理半透明效果, YES为开启, NO为关闭, iOS7以后默认为YES
    UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blueColor];
    button.frame = CGRectMake(0, 0, 200, 200);
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    // 设置为YES时, self.view坐标系从原点开始
    // 设置为NO时, self.view坐标系从navigationBar(0, 64)下开始
    self.navigationController.navigationBar.translucent = NO;
    // 13.改变坐标效果, 与translucent为NO时的效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
    // 页面跳转
    // 1.push 入栈
    // 2.pop 出栈
    // 3.viewcontrollers存放navigationController里所有的控制器
//    self.navigationController.viewControllers
    // 4.栈顶的视图控制器
//    self.navigationController.topViewController
    // 5.visibleViewController 可见视图控制器 (当前显示的)
    
}

#pragma mark - 实现button的点击方法
- (void)handleButton:(UIButton *)button {
    // 将视图控制器入栈
    [self.navigationController pushViewController:[[PushViewCOntroller alloc] init] animated:YES];
}


#pragma mark - 实现barButton的点击方法
- (void)comeBack:(UIBarButtonItem *)barButton {
    NSLog(@"点击了返回");
}
- (void)comeGo:(UIBarButtonItem *)barButton {
    NSLog(@"点击了");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
